<?php if(!empty($this->params) && count($this->params)>0 && !((count($this->params)==1) && isset($this->params['currency']))):?>

<script type="text/javascript">
<!--
// FIXME AAAA!!! перепишіть мене срочно!
function delSearch(id){
	$('#'+id).remove();
	$('#leftSearchForm').submit();
	return false;
}

function delPrice(){
	$('#mypricefrom').remove();
	$('#mypriceto').remove();
	$('#leftSearchForm').submit();
	return false;
}
//-->
</script>
<?php if(isset($this->params['category_only'])){return;} ?>
    <div class="search-parameter-box corner-all">
        <div class="sidebar-caption">Параметры поиска</div>
        <form method='get' action='search' class='search-param' id="leftSearchForm">

            <div style="display:none;">
            <input type='hidden' name='search' value="true" />
            <input type='hidden' name='params[price][currency]' value="1" />
            </div>

            <?php if(isset($this->params['marks'])):  ?>
                <dl class="search-parameter">
                    <dt>Марка</dt>
                      <?php foreach($this->params['marks'] as $marks):?>
                          <dd>
                              <input type='hidden' class='search-param-mark' name='markmodel[][mark]' id="mymark_<?= $marks['markId']; ?>" value='<?= $marks['markId'] ?>' />
                              <?php if($marks['comparison']=='neq'):?>
                                  кроме <a class='search-param-mark' name='no_marks' href='search-params.phtml#' id='mark_<?= $marks['markId']; ?>'><?= $marks['name']; ?></a>
                              <?php else:  ?>
                                  <a href='search-params.phtml#' onclick="return delSearch('mymark_<?= $marks['markId']; ?>');" ><?= $marks['name']; ?></a>
                              <?php endif; ?>
                          </dd>
                      <?php  endforeach;?>
                </dl>
            <?php endif; ?>


            <?php if(isset($this->params['models'])):?>
                <dl class="search-parameter">
                    <dt>Модель</dt>
                      <?php  foreach($this->params['models'] as $models):?>
                          <dd>
                              <input type='hidden' class='search-param-model' name='markmodel[][model]' id="mymodel_<?= $models['modelId']; ?>" value='<?= $models['modelId'] ?>' />
                              <?php if($models['comparison']=='neq'):?>
                                  кроме <a href='search-params.phtml#' class='search-param-model'><?= $models['name']; ?></a>
                              <?php else:  ?>
                                  <a href='search-params.phtml#' class='search-param-model' onclick="return delSearch('mymodel_<?= $models['modelId']; ?>');"><?= $models['name']; ?></a>
                              <?php endif; ?>
                          </dd>
                      <?php endforeach; ?>
                </dl>
            <?php endif; ?>


        <?php if(isset($this->params['price'])): ?>
            <dl class="search-parameter">
                <dt>Цена</dt>
                  <?php
                      $min_price = array();
                   	  $max_price = array();
                   	  $price = array();
               	  ?>

                  <?php foreach ($this->params['price'] as $prices): ?>
                      <?php
                          if(in_array('gt',$prices)) $min_price[] = $prices['value'];
            	          elseif (in_array('lt',$prices)) $max_price[] = $prices['value'];
            	          elseif (in_array('eq',$prices)) $price[] = $prices['value'];
            	      ?>
                  <?php endforeach;?>

                  <?php
                  $lenght=count($min_price);
                  if(!$lenght)$lenght=count($max_price);
                  if($lenght>0){
                      for($i=0;$i<$lenght;$i++){
                          if(!isset($min_price[$i]))$min_price[$i]=0;
                          if(!isset($max_price[$i]))$max_price[$i]='max';
?>
                        <dd>
                            <a href='search-params.phtml#' onclick='return delPrice();'><?= $min_price[$i]." - " .$max_price[$i]; ?></a>
                            <input type='hidden' name='price[to]' id="mypricefrom" value='<?= $max_price[$i]; ?>' />
                            <input type='hidden' name='price[from]' id="mypriceto" value='<?= $min_price[$i]; ?>' />
                        </dd>
  <?php
                      }
                  }
                  ?>

                  <?php if((count($price))>0):?>
          	          <?php foreach($price as $value):?>
                          <dd>
                              <a href='search/search?q=<?= $value ?>$ '><?= $value; ?></a>
                          </dd>
                      <?php endforeach; ?>
                 <?php  endif; ?>

        	</dl>
        <?php endif; ?>


        <?php if(isset($this->params['year'])): 	?>
        <dl class="search-parameter">
            <dt>Год выпуска</dt>
            <?php
               	  if((count($this->params['year']))==1){
               	       if(in_array('gt',$this->params['year'][0])){
               	       	   $min_year = $this->params['year'][0]['value']; ?>

               	       	   <dd>
                               от <a href='search-params.phtml#' onclick="return delSearch('myyearfrom_<?= $min_year; ?>');"><?= $min_year; ?></a>
                               <input type='hidden' name='params[year][from]' id="myyearfrom_<?= $min_year; ?>" value='<?= $min_year; ?>' />
                           </dd>
               	       	   <?php }
                       elseif(in_array('lt',$this->params['year'][0])){
                       	   $max_year = $this->params['year'][0]['value']; ?>
                           <dd>
                               до <a href='search-params.phtml#' onclick="return delSearch('myyearto_<?= $max_year; ?>');"><?= $max_year; ?></a>
                               <input type='hidden' name='params[year][to]' id="myyearto_<?= $max_year; ?>" value='<?= $max_year; ?>' />
                           </dd>
                           <?php }
        	           elseif (in_array('eq',$this->params['year'][0])){
        	           	   $year = $this->params['year'][0]['value'];   ?>

                            <dd>
                                <a href='search-params.phtml#' onclick="return delSearch('myyear_<?= $year; ?>');"><?= $year; ?></a>
                                <input type='hidden' name='year[]' id="myyear_<?= $year ?>" value='<?= $year ?>' />
                            </dd>
        	          <?php  }
               	   } else {
                   	   $min_year = array();
                   	   $max_year = array();
                   	   $year = array();
                       foreach ($this->params['year'] as $years){
            	           if(in_array('gt',$years)) $min_year[] = $years['value'];
            	           elseif (in_array('lt',$years)) $max_year[] = $years['value'];
            	           elseif (in_array('eq',$years)) $year[] = $years['value'];
                       }

                       if(!empty($min_year)){
                       	   $lenght = count($min_year);
                           for($i=0;$i<$lenght;$i++){
                                 ?>
                                       <dd>
                                           <a href='search-params.phtml#' onclick="return delSearch('myyearfrom_<?= $min_year[$i]; ?>');"><?= $min_year[$i]; ?></a> -
                                           <a href='search-params.phtml#' onclick="return delSearch('myyearto_<?= $max_year[$i]; ?>');"><?= $max_year[$i]; ?></a>
                                           <input type='hidden' name='params[year][to]' id="myyearto_<?= $max_year[$i]; ?>" value='<?= $max_year[$i]; ?>' />
                                           <input type='hidden' name='params[year][from]' id="myyearfrom_<?= $min_year[$i]; ?>" value='<?= $min_year[$i]; ?>' />
                                       </dd>
                                 <?php
                           }
                        }
                        if(!empty($year)) {
              	            foreach($year as $value){
            ?>
                                <dd>
                                    <a href='search-params.phtml#' onclick="return delSearch('myyear_<?= $value; ?>');"><?= $value; ?></a>
                                    <input type='hidden' name='year[]' id="myyear_<?= $value ?>" value='<?= $value ?>' />
                                </dd>
            <?php
              	            }
                        }
               	   }
        ?>
        </dl>
        <?php endif; ?>

        <?php if(isset($this->params['states'])): ?>
            <dl class="search-parameter">
               <dt>Область</dt>
                <?php  foreach($this->params['states'] as $states):?>
                   <dd>
                      <input type='hidden' class='search-param-state' id="mystate_<?= $states['stateId'] ?>" name='states[]' value='<?= $states['stateId'] ?>' />
                      <?php if($states['comparison']=='neq'):?>
                             кроме <a href='search-params.phtml#' class='search-param-state'><?= $states['name']; ?></a>
                      <?php else:  ?>
                              <a href='search-params.phtml#'  onclick="return delSearch('mystate_<?= $states['stateId'] ?>');" class='search-param-state'><?= $states['name']; ?></a>
                      <?php endif;?>
                  </dd>
                  <?php endforeach; ?>
             </dl>
        <?php endif;?>


        <?php if(isset($this->params['cities'])): ?>
        <dl class="search-parameter">
           <dt>Город</dt>
             <?php  foreach($this->params['cities'] as $cities):?>
                 <dd>
                      <input type='hidden' class='search-param-city' id="mycity_<?= $cities['cityId'] ?>" name='cities[]' value='<?= $cities['cityId'] ?>' />
                      <?php if($cities['comparison']=='neq'):?>
                          кроме <a href='search-params.phtml#' class='search-param-city'><?= $cities['name']; ?></a>
                      <?php else:  ?>
                          <a href='search-params.phtml#' onclick="return delSearch('mycity_<?= $cities['cityId'] ?>');" class='search-param-city'><?= $cities['name']; ?></a>
                      <?php endif;?>
                  </dd>
             <?php endforeach;?>
        </dl>
        <?php endif;?>


        <?php if(isset($this->params['color'])):?>
            <dl class="search-parameter">
        	    <dt>Цвет</dt>
                 <?php  foreach($this->params['color'] as $color):?>
                     <dd>
                      <input type='hidden' class='search-param-color' id="mycolor_<?= $color['colorId'] ?>" name='color[]' value='<?= $color['colorId'] ?>' />
                      <?php if($color['comparison']=='neq'):?>
                          кроме <a href='search-params.phtml#' onclick="return delSearch('mycolor_<?= $color['colorId'] ?>');" class='search-param-color'><?= $color['name']; ?></a>
                      <?php else:  ?>
                              <a href='search-params.phtml#' onclick="return delSearch('mycolor_<?= $color['colorId'] ?>');" class='search-param-color'><?= $color['name']; ?></a>
                      <?php endif; ?>
                    </dd>
                  <?php endforeach; ?>
             </dl>
        <?php endif;?>

        <?php if(isset($this->params['gear'])):?>
            <dl class="search-parameter">
                  <dt>Коробка передач</dt>
                 <?php  foreach($this->params['gear'] as $gear):?>
                  <dd>
                      <input type='hidden' class='search-param-gear' id="mygear_<?= $gear['gearId'] ?>" name='gear' value='<?= $gear['gearId'] ?>' />
                      <?php if($gear['comparison']=='neq'):?>
                          кроме
                      <?php endif; ?>
                             <a href='search-params.phtml#' onclick="return delSearch('mygear_<?= $gear['gearId'] ?>');" class='search-param-gear'><?= $gear['name']; ?></a>

                  </dd>
               <?php endforeach; ?>
            </dl>
        <?php endif; ?>

        <?php if(isset($this->params['fuel'])):?>
            <dl class="search-parameter">
                <dt>Тип топлива</dt>
                 <?php  foreach($this->params['fuel'] as $fuel):?>
                     <dd>
                      <input type='hidden' class='search-param-fuel' id="myfuel_<?= $fuel['fuelId'] ?>" name='fuel' value='<?= $fuel['fuelId'] ?>' />
                      <?php if($fuel['comparison']=='neq'):?>
                          кроме
                      <?php endif;  ?>
                          <a href='search-params.phtml#' onclick="return delSearch('myfuel_<?= $fuel['fuelId'] ?>');" class='search-param-fuel'><?= $fuel['name']; ?></a>
                      </dd>
               <?php endforeach; ?>
             </dl>
        <?php endif; ?>

        <?php if(isset($this->params['exchange_type'])):?>
            <dl class="search-parameter">
                  <dt>Тип обмена</dt>
                  <?php foreach($this->params['exchange_type'] as $exchange_type):?>
                      <dd>
                          <a href='search-params.phtml#' onclick="return delSearch('myfuel_<?= $fuel['fuelId'] ?>');" href='search/search?q=<?= $exchange_type ?>'><?= $exchange_type; ?></a>
                      </dd>
                  <?php endforeach; ?>
            </dl>
        <?php endif;?>

        <?php if(isset($this->params['drive'])):?>
            <dl class="search-parameter">
                  <dt>Тип кузова</dt>
                  <?php foreach($this->params['drive'] as $item):?>
                      <dd>
                          <a href='search/search?q=<?= $item ?>'><?= $item; ?></a>
                      </dd>
                  <?php endforeach; ?>
            </dl>
        <?php endif;?>

            <div class='search-button' style='display:none;'>
            	<input type='submit' value='Искать' />
            </div>
        </form>
    </div>
<?php endif;?>